<?php
//
//	file: includes/aucp/color_plugs_forums.php
//	begin: 30/04/2007
//	$Author: christopher $
//	$Revision: 29 $
//	$Date: 2008-07-19 15:59:35 +0000 (Sat, 19 Jul 2008) $
//	license: http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
//
//	description: color plugs for class_forums

if (!defined('IN_PHPBB'))
{
	die("Hacking attempt");
}

class color_forums extends plug_ins
{
	var $user_ids;
	var $data;

	function color_forums()
	{
		$this->user_ids = array();

		return;
	}

	function read()
	{
		global $forums;

		$this->data =& $forums->data;

		return;
	}

	function display($forum_id=0)
	{
		global $user;

		$count_subs = count($this->data[$forum_id]['subs']);

		for ( $i = 0; $i < $count_subs; $i++ )
		{
			$cur_id = $this->data[$forum_id]['subs'][$i];

			$layer_type = $this->data[$cur_id]['forum_type'];

			switch ( $layer_type )
			{
				case POST_CAT_URL:
					$this->display_color_a_cat($cur_id);
					break;
				case POST_FORUM_URL:
					$this->display_color_a_forum($cur_id);
					break;
			}
		}

		$user->read_pool($this->user_ids);

		return;
	}

	function display_color_a_cat($forum_id)
	{
		global $user;

		$count_subs = count($this->data[$forum_id]['subs']);

		for ( $i = 0; $i < $count_subs; $i++ )
		{
			$cur_id = $this->data[$forum_id]['subs'][$i];

			$layer_type = $this->data[$cur_id]['forum_type'];

			switch ( $layer_type )
			{
				case POST_CAT_URL:
				case POST_FORUM_URL:
					$this->display_color_a_forum($cur_id);
					break;
			}
		}

		return;
	}

	function display_color_a_forum($forum_id)
	{
		global $user;

		$last_post_data = $this->data[ $this->data[$forum_id]['sum_last_post_forum_id'] ]['last'];

		if ( !in_array($last_post_data['forum_last_poster'], array(0)) && !isset($user->pool[ $last_post_data['forum_last_poster'] ]) )
		{
			$this->user_ids[ $last_post_data['forum_last_poster'] ] = true;
		}

		return;
	}

	function display_a_forum($forum_id=0, $tpl_switch='')
	{
		global $template, $user, $colors;

		$last_post_data = empty($this->data[$forum_id]['sum_last_post_forum_id']) ? array() : $this->data[ $this->data[$forum_id]['sum_last_post_forum_id'] ]['last'];
		$last_post = !empty($last_post_data) && !empty($last_post_data['forum_last_time']);
		if ( $last_post )
		{
			if ( empty($last_post_data['forum_last_username']) )
			{
				$last_post_data['forum_last_poster'] = ANONYMOUS;
				$last_post_data['forum_last_username'] = $user->lang('Guest');
				$user->pool[ ANONYMOUS ]['username'] = $user->lang('Guest');
			}
			else
			{
				$user->pool[ ANONYMOUS ]['username'] = $last_post_data['forum_last_username'];
			}

			$template->assign_lastblock_vars($tpl_switch, array(
				'S_LAST_POSTER' => $colors->get_user_color($user->pool[ $last_post_data['forum_last_poster'] ]['user_group_id'], $user->pool[ $last_post_data['forum_last_poster'] ]['user_session_time']),
			));
		}

		return;
	}
}

?>